BIA Templates
This document explains how the configure and maintain the BIA templates used by the BIAToolKit when creating or migrating a project.
Principle
When packaging a new version of BIA Framework, the project BIADemo is used as template reference to create the associated BIATemplate for the new version
To have the correct templates for a BIA Framework version, we need to configure code of BIADemo and packaging scripts in order to :
- ignore some code areas from
BIADemowhen creating theBIATemplate - ignore some files when creating or migrating a project with the BIAToolKit from the
BIATemplaterelease
The script used for packaging are listed into this documentation
Folders exclusion
Only applicable for Angular project template
Into the packaging script related to the Angular part, the folders of all the features specific to BIADemo must be removed after the copy of all the Angular project.
BIADemo Only markup
Only applicable to .cs files
Adding at the top of a file the markup // BIADemo Only will consider the current file as part of BIADemo only, and will be ignored when the packaging script is executed.
Excluded code area markups
Code area identified by a begin markup starting with Begin and ending with End that will be ignored when templating the project BIADemo to BIATemplate.
These code areas will be removed when packaging BIADemo to BIATemplate with the packaging scripts.
Prefix theses markups by the following according to the file type :
.cs:// {Markup}.ts:// {Markup}.json:// {Markup}.html:<!-- {Markup} -->
BIADemo
Markup begin : Begin BIADemo
Markup end : End BIADemo
Code in these areas is specific code related to BIADemo
BIAToolkit Generation Ignore
Markup begin : Begin BIAToolkit Generation Ignore
Markup end : End BIAToolkit Generation Ignore
Code in these areas is specific code related to BIADemo but required to perform the unit tests of BIAToolKit Templates (see documentation).
Except BIADemo markup
Into the code, the markup // Exception BIADemo will be replaced by an empty string in order to apply the next instruction when packaging the BIATemplate.
It must be used before a BIADemo excluded code area.
public class Example
{
// Except BIADEMO public const string Version = "0.0.0";
// Begin BIADemo
public const string Version = "1.0.0-beta";
// End BIADemo
}
public class Example
{
public const string Version = "0.0.0";
}
- Code between markups
BIADemohas been removed // Except BIADEMOhas been deleted to use the next code of the line
Template Features
Into the .bia folder of BIADemo (and any BIATemplate version) exists the file BiaToolKit_FeatureSetting.json that enumerates the differente features available for the current BIA Framework version used by the BIATemplate.
These features are used by the BIAToolKit to create or migrate a project. The configuration of them is usefull to exclude some code, folders or files when they are selected or not.
[
{
"Id": 1,
"DisplayName": "Feature 1",
"Description": "First example feature",
"IsSelected": true,
"Tags": [
"BIA_FEATURE1_TAG"
],
"FoldersToExcludes": [
".*FolderToExclude.*$"
],
"DisabledFeatures": [2]
},
{
"Id": 2,
"DisplayName": "Feature 2",
"Description": "Second example feature",
"IsSelected": true,
"Tags": [
"BIA_FEATURE2_TAG"
]
},
]
You can configure for each feature :
Id: the unique identifier of the featureDisplayName: the display name of the feature (display value of the feature list from the BIAToolKit)Description: the description of the feature (displayed into the tooltip of the feature from the BIAToolKit)IsSelected: default selection of the feature for the current project creation or migrationTags(optionnal) : list of tags that are related to the current feature used intoBIADemo(thenBIATemplateone packaged) to identify code that is specific to the feature, and excluded if the feature is not selected when creating or migrating a projectinfoAll tags should began with
BIA_FoldersToExcludes(optionnal) : list of folders regex from theBIATemplateto exclude for the project creation or migrationDisabledFeatures(optionnal) : list of feature's identifier that will be disabled automatically when the current one is not selected
Change the order of the features display into the BIAToolKit by changing the order of the features into the .json
Tags usage
.NET conditions
First, you must declare your BIA_FEATURE_TAG as project constant into all the target .csproj that will be concerned by conditions with this tag into BIADemo
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<DefineConstants>BIA_FEATURE_TAG</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<DefineConstants>BIA_FEATURE_TAG</DefineConstants>
</PropertyGroup>
</Project>
You will be able then to remove this constant to test into BIADemo if your conditions are working well.
All the defined constants into BIADemo (then BIATemplate) will be removed when creating or migrating a project by the BIAToolKit
Remove file from project condition
Add an ItemGroup into your csproj like following :
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup Label="Bia_ItemGroup_BIA_FEATURE_TAG" Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants)', '\bBIA_FEATURE_TAG\b'))">
</ItemGroup>
</Project>
ItemGroup.Labelmust corresponds to the templateBia_ItemGroup_{FEATURE_TAG}Conditionmeans that the currentItemGroupwill be considered only if there is no defined constantBIA_FEATURE_TAG
Add then into your ItemGroup all the Compile instruction with Remove attribute for the files that must be excluded if the condition is false :
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup Label="Bia_ItemGroup_BIA_FEATURE_TAG" Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants)', '\bBIA_FEATURE_TAG\b'))">
<Compile Remove="**\*Pattern*.cs" />
<Compile Remove="**\Pattern.cs" />
</ItemGroup>
</Project>
Set the Remove attribute with following :
**\*Pattern*.cs: will exclude all the files that containsPatterninto the.csfile name**\Pattern.cs: will exclude all the files that matchesPattern.csfile name
- These operations of file exclusion are performed by the BIAToolKit when creating or migrating a project
- The
ItemGrouprelated to theBia_ItemGroup_{FEATURE_TAG}label will be removed by the BIAToolKit when creating or migrating a project
Remove project reference condition
Add a Condition attribute to your project reference like following :
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="OtherProject.csproj" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants)', '\BUSE_FEATURE_TAG\b'))" />
</ItemGroup>
</Project>
Here, the project will be add as reference into BIADemo project only if the constant USE_FEATURE_TAG is defined into the project.
The project reference will be removed when creating or migrating a project with BIAToolKit if the corresponding feature is not selected
Code condition
Use directly into the code the conditions with your BIA_FEATURE_TAG constant :
public class MyService()
{
#if BIA_FEATURE_TAG
public void SpecificMethod()
{
// [...]
}
#endif
}
You can use #else condition :
public class MyService()
{
#if BIA_FEATURE_TAG
public void SpecificMethod()
{
// [...]
}
#else
public void CommonMethod()
{
// [...]
}
#endif
}
You can use || and/or && operators into your condition declaration between different tags (only support top level conditions)
Other cases
Simply use the tags as code area as seen for .NET part like following :
{
// if BIA_FEATURE_TAG || BIA_OTHER_FEATURE_TAG
"specificCode": "example"
// endif
}
export class Example
{
// if BIA_FEATURE_TAG && BIA_OTHER_FEATURE_TAG
specificCode: string;
// endif
}
Only compatible for // if {FEATURE_TAG} and // endif markups